package com.pureut.system.controller;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.ProductBatchReporting;
import com.pureut.system.domain.ProductRepairRecord;
import com.pureut.system.domain.vo.ProductBatchReportingVo;
import com.pureut.system.service.IProductBatchReportingService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2025-04-09 15:57:31
 * @Desc: 产品批次报工记录表Controller
 */
@RestController
@RequestMapping("/system/productBatchReporting")
public class ProductBatchReportingController extends BaseController {

    /**
     * 产品批次报工记录表Service
     */
    @Resource
    private IProductBatchReportingService productBatchReportingService;

    /**
     * 查询产品批次报工记录表列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productBatchReporting-list")
    @GetMapping("/list")
    public TableDataInfo list(ProductBatchReportingVo productBatchReportingVo) {
        startPage();
        LambdaQueryWrapper<ProductBatchReporting> resultQuery = new LambdaQueryWrapper<ProductBatchReporting>();
        if(ObjectUtil.isNotNull(productBatchReportingVo.getProductCode())){
            resultQuery.like(ProductBatchReporting::getProductCode, productBatchReportingVo.getProductCode());
        }
        if(ObjectUtil.isNotNull(productBatchReportingVo.getProcessCode())){
            resultQuery.like(ProductBatchReporting::getProcessCode, productBatchReportingVo.getProcessCode());
        }
        if(ObjectUtil.isNotNull(productBatchReportingVo.getProcessName())){
            resultQuery.like(ProductBatchReporting::getProcessName, productBatchReportingVo.getProcessName());
        }
        if(ObjectUtil.isNotNull(productBatchReportingVo.getStartTime())&&ObjectUtil.isNotNull(productBatchReportingVo.getEndTime())){
            resultQuery.between(ProductBatchReporting::getCreatedTime, productBatchReportingVo.getStartTime(),productBatchReportingVo.getEndTime());
        }
        return getDataTable(productBatchReportingService.list(resultQuery));
    }


    /**
     * 获取产品批次报工记录表详细信息
     * @param: id 产品批次报工记录表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productBatchReporting-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(productBatchReportingService.getById(id));
    }

    /**
     * 新增产品批次报工记录表
     * @param: productBatchReporting 产品批次报工记录表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productBatchReporting-add")
    @PostMapping
    public AjaxResult add(@RequestBody ProductBatchReportingVo productBatchReportingVo) {
        return toAjax(productBatchReportingService.save(productBatchReportingVo));
    }

    /**
     * 修改产品批次报工记录表
     * @param: productBatchReporting 产品批次报工记录表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productBatchReporting-edit")
    @PutMapping
    public AjaxResult edit(@RequestBody ProductBatchReportingVo productBatchReportingVo) {
        return toAjax(productBatchReportingService.updateById(productBatchReportingVo));
    }

    /**
     * 删除产品批次报工记录表
     * @param: id 产品批次报工记录表主键
     * @return: Json工具类对象
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productBatchReportingService.removeByIds(Arrays.asList(ids)));
    }
}
